//
//  WalkmanViewController.swift
//  ShimaPlayer
//
//  Created by michael on 2025/7/9.
//

import UIKit

class WalkmanViewController: UIViewController {

    private lazy var backButton: UIButton = {
        let button = UIButton(type: .system)
        button.setImage(
            UIImage(named: "nav_back_gray")?.withRenderingMode(.alwaysOriginal), for: .normal)
        button.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside)
        return button
    }()
    
    private lazy var settingsButton: UIButton = {
        let button = UIButton(type: .system)
        button.setImage(
            UIImage(named: "nav_btn_settings")?.withRenderingMode(.alwaysOriginal), for: .normal)
        button.contentMode = .center
        button.addTarget(self, action: #selector(settingsButtonTapped), for: .touchUpInside)
        return button
    }()

    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.text = "随身听"
        label.textColor = UIColor(hexString: "FFFFFF")
        label.font = .systemFont(ofSize: 17, weight: .medium)
        label.textAlignment = .center
        return label
    }()

    private lazy var summaryView: WordListSummaryView = {
        let view = WordListSummaryView()
        return view
    }()
    
    private lazy var wordListView: WordListView = {
        let view = WordListView(title: "") { [weak self] in
            self?.onTapAddWord()
        }
        return view
    }()
    
    private lazy var miniPlayer: MiniPlayer = {
        let player = MiniPlayer()
        player.onPlayButtonTappedAction = { [weak self] in
            self?.onPlayButtonTapped()
        }
        let tap = UITapGestureRecognizer(target: self, action: #selector(onTapMiniPlayer))
        player.addGestureRecognizer(tap)
        return player
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.navigationBar.isHidden = true
        setupUI()

        let list = [WordItemModel(original: "案内します③", translation: "陪同，带路", type: "他サ"),
                    WordItemModel(original: "案内します③", translation: "陪同，带路", type: "他サ"),
                    WordItemModel(original: "案内します③", translation: "陪同，带路", type: "他サ")]
        wordListView.dataSource = list
    }
    
    func setupUI() {
        let bgImage = UIImage.gradientImage(colors: [UIColor(hexString: "#1B2340"), UIColor(hexString: "#1C2341"), UIColor(hexString: "#363F65")],
                                            size: view.bounds.size,
                                            startPoint: CGPoint(x: 0.25, y: 0.5),
                                            endPoint: CGPoint(x: 0.75, y: 0.5),
                                            locations: [0, 0.15, 0.46],
                                            transform: CATransform3DMakeAffineTransform(CGAffineTransform(a: 1.2, b: 1.24, c: -1.24, d: 0.25, tx: 0.51, ty: -0.36))
        )
        let bgView = UIImageView(image: bgImage)
        view.addSubview(bgView)
        bgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        view.addSubview(backButton)
        backButton.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(10)
            make.leading.equalToSuperview().offset(16)
            make.height.equalTo(44)
            make.width.equalTo(20)
        }

        view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(backButton)
            make.centerX.equalToSuperview()
        }

        view.addSubview(settingsButton)
        settingsButton.snp.makeConstraints { make in
            make.centerY.equalTo(backButton)
            make.trailing.equalToSuperview().inset(6)
            make.width.height.equalTo(44)
        }

        view.addSubview(summaryView)
        summaryView.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(25)
            make.horizontalEdges.equalToSuperview().inset(16)
        }

        view.addSubview(wordListView)

        view.addSubview(miniPlayer)
        miniPlayer.snp.makeConstraints { make in
            make.leading.bottom.trailing.equalToSuperview()
            make.height.equalTo(Size.bottomSafeAreaHeight + 67)
        }

        wordListView.snp.makeConstraints { make in
            make.top.equalTo(summaryView.snp.bottom).offset(18)
            make.horizontalEdges.equalToSuperview()
            make.bottom.equalTo(miniPlayer.snp.top)
        }

    }
    
    // MARK: - Actions
    @objc private func backButtonTapped() {
        navigationController?.popViewController(animated: true)
    }

    @objc private func onTapCreateWordList() {
        let list = [WordItemModel(original: "案内します③", translation: "陪同，带路", type: "他サ"),
                    WordItemModel(original: "案内します③", translation: "陪同，带路", type: "他サ"),
                    WordItemModel(original: "案内します③", translation: "陪同，带路", type: "他サ")]
        wordListView.dataSource = list
    }
    
    @objc private func settingsButtonTapped() {
        let menu = WordListMenu()
        let popup = PopupView(contentView: menu, style: .custom(sourceView: settingsButton, size: CGSize(width: 100, height: 200)))
        menu.configureTapAction { [weak self] index in
            self?.onMenuItemTapped(index)
            popup.dismiss()
        }
        popup.show(in: self) { make in
            make.top.equalToSuperview().offset(Size.topBarHeight)
            make.trailing.equalToSuperview().inset(37)
            make.width.equalTo(117)
            make.height.equalTo(109)
        }

    }
    
    @objc private func onPlayButtonTapped() {
        
    }

    @objc private func onTapMiniPlayer() {
        let vc = WalkmanPlayerViewController()
        vc.modalPresentationStyle = .fullScreen
        present(vc, animated: true, completion: nil)   
    }

    private func showCoverPicker() {
//        let picker = UIImagePickerController()
//        picker.delegate = self
//        picker.sourceType = .photoLibrary
//        present(picker, animated: true, completion: nil)
    }
    
    private func onTapEditWordListName() {
        
    }

    private func onTapAddWord() {
        
    }

    private func onMenuItemTapped(_ index: Int) {
        print("onMenuItemTapped: \(index)")
        switch index {
        case 0:
            onTapSwitchList()
        case 1:
            onTapCreateNewList()
        case 2:
            onTapDeleteWordList()
        default:
            break
        }
    }
    
    private func onTapSwitchList() {
        let list = [
            WordListItemModel(title: "250307T1新编日语教程第1册词单第1册词单第1册词单", cover: "cover1", isCurrent: true),
            WordListItemModel(title: "250307T2新编日语教程第2册词单", cover: "cover2", isCurrent: false),
            WordListItemModel(title: "250307T3新编日语教程第3册词单", cover: "cover3", isCurrent: false),
        ]
        let alert = SwitchWordListMenu()
        alert.list = list
        let popup = PopupView(contentView: alert, style: .alert())
        popup.show(in: self) { make in
            make.horizontalEdges.equalToSuperview().inset(16)
            make.center.equalToSuperview()
        }
    }
    
    private func onTapCreateNewList() {
        
    }
    
    private func deleteList() {

    }

    private func onTapDeleteWordList() {
        let alert = CommonAlertView(icon: UIImage(named: "icon_alert_delete"), title: "确定删除词单？", cancelTitle: "再想想", confirmTitle: "确定删除")
        let popup = PopupView(contentView: alert, style: .alert())
        popup.show(in: self) { make in
            make.horizontalEdges.equalToSuperview().inset(64)
            make.center.equalToSuperview()
        }
        alert.configureAction(cancel: {
            popup.dismiss()
        }) { [weak self] in
            popup.dismiss()
            self?.deleteList()
        }
    }

}

class WordListSummaryView: UIView {

    private let coverView: UIImageView = {
        let view = UIImageView()
        view.contentMode = .scaleAspectFill
        view.clipsToBounds = true
        view.layer.cornerRadius = 10
        return view
    }()
    
    private let wordListNameLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString: "FFFFFF")
        label.font = .systemFont(ofSize: 15, weight: .bold)
        label.textAlignment = .center
        label.text = "250307C1新编日语第2册词单"
        return label
    }()
    
    private let avatarView: UIImageView = {
        let view = UIImageView()
        view.contentMode = .scaleAspectFill
        view.clipsToBounds = true
        view.layer.cornerRadius = 6
        return view
    }()

    private let usernameLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString: "FFFFFF")?.withAlphaComponent(0.66)
        label.font = .systemFont(ofSize: 10, weight: .medium)
        label.text = "由你创建"
        return label
    }()

    private let createdTimeLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString: "FFFFFF")?.withAlphaComponent(0.5)
        label.font = .systemFont(ofSize: 10, weight: .medium)
        label.text = "创建于2025年03月08日"
        return label
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        avatarView.backgroundColor = .red
        coverView.backgroundColor = .red
        
        let userStack = UIStackView(arrangedSubviews: [avatarView, usernameLabel])
        userStack.axis = .horizontal
        userStack.spacing = 4
        userStack.alignment = .center

        let vStack = UIStackView(arrangedSubviews: [wordListNameLabel, userStack, createdTimeLabel])
        vStack.axis = .vertical
        vStack.spacing = 9
        vStack.alignment = .leading
        vStack.distribution = .fill
        vStack.setContentHuggingPriority(.required, for: .vertical)
        
        addSubview(coverView)
        addSubview(vStack)
        
        vStack.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(15)
            make.leading.equalTo(coverView.snp.trailing).offset(16)
            make.right.equalToSuperview().inset(16)
        }
                
        coverView.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.leading.equalToSuperview().offset(16)
            make.width.height.equalTo(105)
        }
        
        avatarView.snp.makeConstraints { make in
            make.width.height.equalTo(12)
        }
        
    }
}

class MiniPlayer: UIView {
    
    override var bounds: CGRect {
        didSet {
            setupShadow()
        }
    }

    var onPlayButtonTappedAction: (() -> Void)?

    private let progressView: UIProgressView = {
        let view = UIProgressView()
        view.progressTintColor = UIColor(hexString: "#15CC9D")
        view.trackTintColor = .clear
        return view
    }()

    private let coverView: UIImageView = {
        let view = UIImageView()
        view.contentMode = .scaleAspectFill
        view.clipsToBounds = true
        view.layer.cornerRadius = 14
        return view
    }()

    private let lyricsLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString: "#1C1F1E")
        label.font = .systemFont(ofSize: 16, weight: .medium)
        label.textAlignment = .center
        label.text = "よろしくお願いします"
        return label
    }()

    private lazy var playButton: UIButton = {
        let button = UIButton(type: .system)
        button.setImage(UIImage(named: "btn_play")?.withRenderingMode(.alwaysOriginal), for: .normal)
        button.setImage(UIImage(named: "btn_pause")?.withRenderingMode(.alwaysOriginal), for: .selected)
        button.addTarget(self, action: #selector(onPlayButtonTapped), for: .touchUpInside)
        return button
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        coverView.backgroundColor = .red
        progressView.progress = 0.6
        
        backgroundColor = UIColor(hexString: "#FFFFFF")
        layer.masksToBounds = false

        addSubview(progressView)
        progressView.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
            make.height.equalTo(1)
        }

        let coverBgView = UIImageView(image: UIImage(named: "bg_cd_cover"))
        addSubview(coverBgView)
        coverBgView.addSubview(coverView)
        coverBgView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(13)
            make.leading.equalToSuperview().offset(16)
            make.width.height.equalTo(42)
        }
        coverView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.height.equalTo(28)
        }

        addSubview(lyricsLabel)
        lyricsLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(23)
            make.leading.equalTo(coverBgView.snp.trailing).offset(16)
        }

        addSubview(playButton)
        playButton.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(16)
            make.leading.equalTo(lyricsLabel.snp.trailing).offset(16)
            make.trailing.equalToSuperview().inset(26)
            make.width.height.equalTo(32)
        }

    }

    @objc private func onPlayButtonTapped() {
        onPlayButtonTappedAction?()
    }
    
    private func setupShadow() {
        layer.shadowColor = UIColor.black.withAlphaComponent(0.05).cgColor
        layer.shadowOffset = CGSize(width: 0, height: -2)
        layer.shadowRadius = 6
        layer.shadowOpacity = 1.0
        layer.masksToBounds = false
    }
}

class WordListMenu: UIView {

    var onClick: ((Int) -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    convenience init() {
        self.init(frame: .zero)
        setupUI()
    }
    
    private func setupUI() {
        let subviewsList = ["切换词单", "新建词单", "删除此词单"].enumerated().map { index, text in
            let view = UIView()
            let label = UILabel()
            label.text = text
            label.textColor = UIColor(hexString: "#000000")
            label.font = .systemFont(ofSize: 13, weight: .medium)
            label.tag = index
            label.textAlignment = .center
            label.isUserInteractionEnabled = true
            label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(menuItemTapped)))
            view.addSubview(label)

            label.snp.makeConstraints { make in
                make.edges.equalToSuperview()
                make.width.equalTo(117)
            }

            if index != 2 {
                let separator = UIView(frame: CGRect(x: 0, y: 0, width: 90, height: 1))
                separator.backgroundColor = UIColor(hexString: "#D9D9D9")
                view.addSubview(separator)

                separator.snp.makeConstraints { make in
                    make.horizontalEdges.equalToSuperview().inset(14)
                    make.bottom.equalToSuperview()
                    make.height.equalTo(0.5)
                }
            }

            return view
        }

        let menu = UIStackView(arrangedSubviews: subviewsList)
        menu.axis = .vertical
        menu.distribution = .fillEqually
        menu.alignment = .center
        menu.backgroundColor = UIColor(hexString: "#FFFFFF")
        menu.layer.cornerRadius = 10
        addSubview(menu)
        menu.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    func configureTapAction(_ action: @escaping ((Int) -> Void)) {
        onClick = action
    }
    
    @objc private func menuItemTapped(_ sender: UITapGestureRecognizer) {
        onClick?(sender.view?.tag ?? 0)
    }
    
}

class CommonAlertView: UIView {
    
    var icon: UIImage?
    var title: String = ""
    var cancelTitle: String?
    var confirmTitle: String = ""
    var cancelColor: UIColor?
    var confirmColor: UIColor?
    var cancelAction: (() -> Void)?
    var confirmAction: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    convenience init(icon: UIImage? = nil,
                     title: String,
                     cancelTitle: String? = nil,
                     confirmTitle: String,
                     cancelColor: UIColor? = UIColor(hexString: "#15CC9D"),
                     confirmColor: UIColor? = UIColor(hexString: "#868F99"),
                     cancelAction: (() -> Void)? = nil,
                     confirmAction: (() -> Void)? = nil) {
        self.init(frame: .zero)
        self.icon = icon
        self.title = title
        self.cancelTitle = cancelTitle
        self.confirmTitle = confirmTitle
        self.cancelAction = cancelAction
        self.confirmAction = confirmAction
        self.confirmColor = confirmColor
        self.cancelColor = cancelColor
        setupUI()
    }
    
    private func setupUI() {
        backgroundColor = .white
        layer.cornerRadius = 20
        layer.masksToBounds = true
        
        let iconView = UIImageView(image: icon)
        iconView.contentMode = .scaleAspectFit
        iconView.isHidden = icon == nil
        
        let titleLabel = UILabel()
        titleLabel.text = title
        titleLabel.textColor = .black
        titleLabel.font = .systemFont(ofSize: 17, weight: .medium)
        
        let dividerV = UIView()
        dividerV.backgroundColor = UIColor(hexString: "#CCCCCC")
        
        let cancelBtn = UIButton(type: .system)
        cancelBtn.setTitle(cancelTitle, for: .normal)
        cancelBtn.setTitleColor(cancelColor, for: .normal)
        cancelBtn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
        cancelBtn.addTarget(self, action: #selector(cancelTapped), for: .touchUpInside)
        
        let dividerH = UIView()
        dividerH.backgroundColor = UIColor(hexString: "#CCCCCC")
        
        let confirmBtn = UIButton(type: .system)
        confirmBtn.setTitle(confirmTitle, for: .normal)
        confirmBtn.setTitleColor(confirmColor, for: .normal)
        confirmBtn.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
        confirmBtn.addTarget(self, action: #selector(confirmTapped), for: .touchUpInside)
        
        addSubview(iconView)
        iconView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(18)
        }
        
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(iconView.snp.bottom).offset(8)
            make.centerX.equalTo(iconView)
        }
        
        addSubview(dividerV)
        dividerV.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(12)
            make.horizontalEdges.equalToSuperview()
            make.height.equalTo(0.5)
        }
        
        addSubview(confirmBtn)
        confirmBtn.snp.makeConstraints { make in
            make.top.equalTo(dividerV.snp.bottom)
            make.leading.bottom.equalToSuperview()
        }
        
        addSubview(dividerH)
        dividerH.snp.makeConstraints { make in
            make.leading.equalTo(confirmBtn.snp.trailing)
            make.top.equalTo(confirmBtn)
            make.bottom.equalToSuperview()
            make.width.equalTo(0.5)
            make.height.equalTo(48)
        }
        
        addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.leading.equalTo(dividerH.snp.trailing)
            make.top.size.equalTo(confirmBtn)
            make.trailing.equalToSuperview()
        }
        
    }

    @objc private func cancelTapped() {
        cancelAction?()
    }
    
    @objc private func confirmTapped() {
        confirmAction?()
    }
    
    func configureAction(cancel: (() -> Void)? = nil,
                         confirm: (() -> Void)? = nil) {
        cancelAction = cancel
        confirmAction = confirm
    }
}

class SwitchWordListMenu: UIView, UITableViewDataSource, UITableViewDelegate {

    var list: [WordListItemModel] = [] {
        didSet {
            tableView.reloadData()
        }
    }
    
    private let tableView: UITableView = {
        let tableView = UITableView()
        tableView.backgroundColor = UIColor(hexString: "FFFFFF")
        tableView.rowHeight = 66
        return tableView
    }()

    init() {
        super.init(frame: .zero)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = UIColor(hexString: "#FFFFFF")
        layer.cornerRadius = 20
        
        tableView.delegate = self
        tableView.dataSource = self
        addSubview(tableView)

        let titleLabel = UILabel()
        titleLabel.text = "随身听词单"
        titleLabel.textColor = UIColor(hexString: "#000000")
        titleLabel.font = .systemFont(ofSize: 16, weight: .medium)
        titleLabel.textAlignment = .center
        titleLabel.layer.shadowColor = UIColor(hexString: "#000000")?.withAlphaComponent(0.1).cgColor
        titleLabel.backgroundColor = UIColor(hexString: "#FFFFFF")
        titleLabel.layer.shadowOpacity = 1
        titleLabel.layer.shadowRadius = 4
        titleLabel.layer.shadowOffset = CGSize(width: 0, height: 2)
        titleLabel.layer.masksToBounds = false
    
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
            make.height.equalTo(55)
        }

        let createButton = UIButton(type: .system)
        createButton.backgroundColor = UIColor(hexString: "#15CC9D")
        createButton.setImage(UIImage(named: "btn_icon_add_white_normal")?.withRenderingMode(.alwaysOriginal), for: .normal)
        createButton.setTitle("新建词单", for: .normal)
        createButton.setTitleColor(UIColor(hexString: "#FFFFFF"), for: .normal)
        createButton.titleLabel?.font = .systemFont(ofSize: 15, weight: .medium)
        createButton.layer.cornerRadius = 18.5
        createButton.addTarget(self, action: #selector(createButtonTapped), for: .touchUpInside)
        addSubview(createButton)
        createButton.snp.makeConstraints { make in
            make.top.equalTo(tableView.snp.bottom).offset(30)
            make.bottom.equalToSuperview().inset(30)
            make.centerX.equalToSuperview()
            make.width.equalTo(102)
            make.height.equalTo(37)
        }
        

        tableView.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(330)
        }
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        list.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: WordListItemCell = WordListItemCell.cell(withTableView: tableView)
        cell.configure(with: list[indexPath.row])
        return cell
    }

    @objc private func createButtonTapped() {
        print("Create button tapped")
    }
}

class WordListItemCell: UITableViewCell {

    private let coverView: UIImageView = {
        let view = UIImageView()
        view.contentMode = .scaleAspectFill
        view.clipsToBounds = true
        view.layer.cornerRadius = 8
        view.layer.shadowColor = UIColor(hexString: "#000000")?.withAlphaComponent(0.1).cgColor
        view.layer.shadowOpacity = 1
        view.layer.shadowRadius = 4
        view.layer.shadowOffset = CGSize(width: 0, height: 2)
        view.layer.masksToBounds = false
        return view
    }()
    
    private let titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString: "#000000")
        label.font = .systemFont(ofSize: 13, weight: .medium)
        return label
    }()

    private let currentView: UILabel = {
        let label = UILabel()
        label.textColor = UIColor(hexString: "#15CC9D")
        label.font = .systemFont(ofSize: 10)
        label.text = "当前词单"
        label.backgroundColor = UIColor(hexString: "#E7F9F5")
        label.layer.cornerRadius = 8.5
        label.clipsToBounds = true
        label.isHidden = true
        label.textAlignment = .center
        return label
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = UIColor(hexString: "#FFFFFF")
        
        coverView.backgroundColor = .red

        addSubview(coverView)
        coverView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(26)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(50)
        }

        addSubview(titleLabel)
        
        addSubview(currentView)
        
        titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(coverView.snp.trailing).offset(10)
            make.trailing.equalToSuperview().inset(81)
            make.centerY.equalToSuperview()
        }
        
        currentView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().inset(21)
            make.centerY.equalToSuperview()
            make.width.equalTo(49)
            make.height.equalTo(17)
        }

    }
    
    func configure(with model: WordListItemModel) {
        titleLabel.text = model.title
        coverView.image = UIImage(named: model.cover)
        currentView.isHidden = !model.isCurrent
    }
}

struct WordListItemModel {
    let title: String
    let cover: String
    var isCurrent = false
    
    init(title: String, cover: String, isCurrent: Bool = false) {
        self.title = title
        self.cover = cover
        self.isCurrent = isCurrent
    }
}
